package com.miage.kangourou.client.calendar;

import java.util.Date;

import com.bradrydzewski.gwt.calendar.client.Calendar;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DatePicker;

public class DatePickerWidget extends GenericWidget {

	private DatePicker datePicker = null;
	
	public DatePickerWidget(KangourouPanel context) {
		super(context, "datepicker");
	}
	
	public Widget createWidget() {
		datePicker = new DatePicker();
		return datePicker;
	}

	public void configureWidget() {
		datePicker.setValue(new Date());
		datePicker.setWidth("100%");
		datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {

			public void onValueChange(ValueChangeEvent<Date> event) {
				CalendarWidget calendarWidget = (CalendarWidget) context.getWidget("calendar");
				Calendar calendar = calendarWidget.getCalendar();
				
				calendar.setDate(event.getValue());
				context.clickChangeDateButton(0);
				
			}
		});
	}

	public DatePicker getDatePicker() {
		return datePicker;
	}


}
